// 引入 pinia
import { defineStore } from 'pinia'
import { user } from '@/api'
import { getToken } from '@/utils/localStoreToken.js'
export const userStore = defineStore('main', {
	state: () => ({
		userInfo: { },
		updateShopCart: false
	}),
	actions: {
		async getUserInfo(){
			let token = getToken()
			try{
				let result = await user.reqGetUserInfo({token})
				if(result.code === 0) {
					this.userInfo = result.userInfo
					return result.userInfo
				}else {
					return Promise.reject('faild')
				}
			}catch(err) {
				return Promise.reject(err)
			}
		},
		clearUserInfo() {
			this.userInfo = { }
		},
		changeUpdateShopCart(){
			console.log(123)
			this.updateShopCart = !this.updateShopCart
		}
	}
})